package pluginMain;

import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;

public class DRICommand
{
	static void onDri(CommandSender sender)
	{
		if (sender.hasPermission("dri.use")) {
			DriThread driThread = new DriThread(sender);
			driThread.start();
		}
	}

	static void onDriadmin(CommandSender sender, String[] args)
	{
		if (sender.hasPermission("dri.admin")) {
			DriadminThread driadminThread = new DriadminThread(sender, args);
			driadminThread.start();
		}
	}
}

class DriThread extends Thread
{
	Player player;

	public DriThread(CommandSender sender)
	{
		player = (Player) sender;
	}

	@Override
	public void run()
	{
		double time = DRIUtils.getTime(player);
		if (time > 0) {
			player.sendMessage(ChatColor.RED + "Next gift will spawn in " + time + " h");
		}
		else if (DRIUtils.setPlayerItems(player)) {
			player.sendMessage(ChatColor.GREEN + "Your gift was sent to your inventory.");
		}
		else {
			player.sendMessage(ChatColor.RED + "You gift list is empty!  please contact gm and report this problem.");
		}

	}
}

class DriadminThread extends Thread
{
	CommandSender sender;
	HumanEntity player;
	String[] args;

	public DriadminThread(CommandSender sen_, String[] arg_)
	{
		sender = sen_;
		player = (HumanEntity) sen_;
		args = arg_;
	}

	@Override
	public void run()
	{
		Inventory inventory = DRIUtils.getInventory(args);
		if (inventory != null) {
			player.openInventory(inventory);
		}
		else {
			sender.sendMessage(ChatColor.RED + "/driadmin set");
			sender.sendMessage(ChatColor.RED + "/driadmin setvip");
			sender.sendMessage(ChatColor.RED + "/driadmin setplayer [Name]");
			sender.sendMessage(ChatColor.RED + "/driadmin setgroup [Name]");
		}
	}

}
